package ntu.sce.fyp.easilocation;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;


public class TestClient {
	
	private static final String TAG = "TestClient";
	private static final String LOGIN_URL = "http://2.easilocation.appspot.com/signIn";
	
	public static void main(String[] args) throws IOException {
		String username = URLEncoder.encode("ichen", "UTF-8");
		String password = URLEncoder.encode("1", "UTF-8");

		URL url = new URL(LOGIN_URL);
		URLConnection connection = url.openConnection();
		connection.setDoOutput(true);

		OutputStreamWriter out = new OutputStreamWriter(
	                              connection.getOutputStream());
		out.write("username=" + username);
		out.write("&password=" + password);
		out.close();

		BufferedReader in = new BufferedReader(
					new InputStreamReader(
					connection.getInputStream()));
					
		String decodedString;

		while ((decodedString = in.readLine()) != null) {
		    System.out.println(decodedString);
		}
		in.close();
	}
}
